package cn.net.yugu.doraemon.springweb.enums;

import java.util.Arrays;

/**
 * @author wanghongli
 * @date 2023/3/21 14:31
 * @description BaseEnum
 **/
public interface BaseEnum {
    String getKey();
    int getValue();

    static <T extends BaseEnum> T getBykey(String key, Class<T> clazz) {
        return Arrays.stream(clazz.getEnumConstants()).filter(x->x.getKey().equals(key)).findFirst().orElse(null);
    }

    static <T extends BaseEnum> T getByValue(int value, Class<T> clazz) {
        return Arrays.stream(clazz.getEnumConstants()).filter(x->x.getValue() == value).findFirst().orElse(null);
    }
}
